/*
 * @Author: lsmi
 * @Date: 2021-11-05 23:18:01
 * @LastEditors: lsmi
 * @LastEditTime: 2021-11-06 10:09:32
 * @FilePath: \base-typescript\src\then.ts
 */
import { readFile } from 'fs'
type Executor<T> = (
  resolve: (result: T) => void,
  reject: (error: unknown) => void
) => void

// interface MyPro<T> {
//   constructor(f: Executor<T>): void
//   then<U>(g: (result: T) => MyPro<U>): MyPro<U>
//   catch<U>(g: (error: unknown) => MyPro<U>): MyPro<U>
// }

class MyPromise<T> {
  constructor(f: Executor<T>) { }
  then<U>(g: (result: T) => MyPromise<U>): MyPromise<U>{

  }
  catch<U>(g: (error: E) => MyPromise<U>): MyPromise<U>{

  }
}

function readFilePromise(path: string): Promise<string> {
  return new Promise((resolve, reject) => {
    readFile(path, (error, result) => {
      if (error) {
        reject(error)
      } else {
        // resolve(result)
      }
    })
  })
}